using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.ContactsDomain;
//using ShivamEMR.Web.Areas.Contacts.Models;
using ShivamEMR.Model.DataInterfaces.ContactsDataInterf;
using ShivamEMR.Model;

namespace ShivamEMR.Web.Areas.Contacts.Controllers
{   
    public class CityController : Controller
    {
		private readonly ICountryRepository countryRepository;
		private readonly ICityRepository cityRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public CityController() 
        {
            countryRepository = Registry.RepositoryFactory.GetCountryRepository();
            cityRepository = Registry.RepositoryFactory.GetCityRepository();
        }

        public CityController(ICountryRepository countryRepository, ICityRepository cityRepository)
        {
			this.countryRepository = countryRepository;
			this.cityRepository = cityRepository;
        }

        //
        // GET: /City/

        public ViewResult Index()
        {
           // return View(cityRepository.AllIncluding(city => city.Country));
            return View(cityRepository.All);
        }

        //
        // GET: /City/Details/5

        public ViewResult Details(System.Guid id)
        {
            return View(cityRepository.Find(id));
        }

        //
        // GET: /City/Create

        public ActionResult Create()
        {
			ViewBag.PossibleCountries = countryRepository.All;
            return View();
        } 

        //
        // POST: /City/Create

        [HttpPost]
        public ActionResult Create(City city)
        {
            if (ModelState.IsValid) {
                cityRepository.InsertOrUpdate(city);
                cityRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleCountries = countryRepository.All;
				return View();
			}
        }
        
        //
        // GET: /City/Edit/5
 
        public ActionResult Edit(System.Guid id)
        {
			ViewBag.PossibleCountries = countryRepository.All;
             return View(cityRepository.Find(id));
        }

        //
        // POST: /City/Edit/5

        [HttpPost]
        public ActionResult Edit(City city)
        {
            if (ModelState.IsValid) {
                cityRepository.InsertOrUpdate(city);
                cityRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleCountries = countryRepository.All;
				return View();
			}
        }

        //
        // GET: /City/Delete/5
 
        public ActionResult Delete(System.Guid id)
        {
            return View(cityRepository.Find(id));
        }

        //
        // POST: /City/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(System.Guid id)
        {
            var city = cityRepository.Find(id);
            cityRepository.Delete(city);
            cityRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

